<h1>View Message</h1>
<fieldset>
<legend><?php $header = $message->subject .' - '.$message->date; echo $header; ?></legend>
<table>
    <tr>
        <td><label><?php if($format==MESSAGE_INBOX){echo 'from : ';}else if($format==MESSAGE_OUTBOX){echo 'to : ';}?></label></td>
        <td><label><?php echo $recipient->name;?></label></td>
        <td><label></label></td>
    </tr>
    <tr>
        <td><label>subject : </label></td>
        <td><label><?php echo $message->subject;?></label></td>
        <td><label></label></td>
    </tr>
    <tr>
        <td><label>message : </label></td>
        <td><label></label></td>
        <td><label></label></td>
    </tr>
    <tr>
        <td></td>
        <td><label><?php echo $message->body;?></label></td>
    </tr>
    <?php if($document){?>
    <tr>
        <td><label>Attachments : </label></td>
    </tr>
    <?php foreach($document as $doc){?>
    <tr>
        <td><label><?php echo $doc->file_url;?></label></td>
        <?php $ext = end(explode('.',$doc->file_url)); 
            if( $ext=="jpg" || $ext=="jpeg" || $ext=="png" || $ext=="bmp" ){
                if($format==MESSAGE_OUTBOX){$folder="sent";}else if($format==MESSAGE_INBOX){$folder="inbox";}
                ?>
                <td><a target="_blank" href="<?php echo base_url();?>message/view_document_page/<?php echo DOCUMENT_PAYMENTFILE.'/'.$doc->document_id;?>"><label>View</label></a></td>
                <td><a target="_blank" href="<?php echo base_url();?>message/download_document/<?php echo $message->message_id.'/'.$doc->role_document_id.'/null/'.$ext.'/'.$folder;?>"><label>Download</label></a></td>
                <?php
            }else{
                ?>
                <td><a target="_blank" href="<?php echo base_url();?>message/view_document_page/<?php echo $doc->role_document_id.'/'.$doc->document_id;?>"><label>View</label></a></td>
                <td><a target="_blank" href="<?php echo base_url();?>message/download_document/<?php echo $message->message_id.'/'.$doc->role_document_id.'/'.$doc->document_id;?>"><label>Download</label></a></td>
                <?php
            }
        ?>
    </tr>
    <?php } }?>
    
</table>
</fieldset>